﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace CommunitySystem.PageView.WordAction
{
    public partial class PositionChangeControl : UserControl
    {
        private readonly WordActionService.WordActionClient _client = null;
        public PositionChangeControl()
        {
            InitializeComponent();
            _client = new WordActionService.WordActionClient();
            _client.GetWord_PostionChangeCompleted += new EventHandler<WordActionService.GetWord_PostionChangeCompletedEventArgs>(_client_GetWord_PostionChangeCompleted);
            _client.DeleteWord_PostionChangeCompleted += (sender1, e1) =>
            {
                SilverlightMessageBoxLibrary.Message.InfoMessage("删除成功");
                PositionChangeControl_Loaded(null, null);
            };
            this.Loaded += new RoutedEventHandler(PositionChangeControl_Loaded);
        }

        void _client_GetWord_PostionChangeCompleted(object sender, WordActionService.GetWord_PostionChangeCompletedEventArgs e)
        {
            dg.ItemsSource = null;
            dg.ItemsSource = e.Result;
        }

        void PositionChangeControl_Loaded(object sender, RoutedEventArgs e)
        {
            _client.GetWord_PostionChangeAsync("1=1");
        }
        private PositionChangeWindow wind = null;
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ImageButton_Click(object sender, RoutedEventArgs e)
        {
            wind = null;
            wind = new PositionChangeWindow(0);
            wind.Show();
            wind.Closed += new EventHandler(wind_Closed);
        }

        void wind_Closed(object sender, EventArgs e)
        {
            if (wind != null && wind.DialogResult == true)
            {
                _client.GetWord_PostionChangeAsync("1=1");
            }
        }

        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ImageButton_Click_1(object sender, RoutedEventArgs e)
        {
            if (dg.SelectedItem != null)
            {
                var entity = dg.SelectedItem as WordActionService.Word_PostionChange;
                wind = new PositionChangeWindow(entity.ID);
                wind.Show();
                wind.Closed += new EventHandler(wind_Closed);
            }
        }


        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ImageButton_Click_2(object sender, RoutedEventArgs e)
        {
            if (dg.SelectedItem != null)
            {
                var entity = dg.SelectedItem as WordActionService.Word_PostionChange;
                _client.DeleteWord_PostionChangeAsync(entity.ID);
               
            }
        }
    }
}
